//39
function combinationSum(candidates, target) {
  let result = [];
  function travel(nums, arr) {
    const sum = arr.reduce((acc, cur) => acc + cur, 0);
    if (sum === target) {
      result.push(arr);
      return;
    }
    if (sum >= target - 1) {
      return;
    }
    nums.forEach((item, index) => {
      travel(nums.slice(index), [...arr, item]);
    });
  }
  travel(candidates, []);
  return result;
}
console.log(combinationSum([2, 3, 6, 7], 7));
console.log(1);
